Repository navigation
Conversation
Co-authored-by: Bernhard Owen Josephus <bernhardoj@users.noreply.github.com>
|
🤖 Web test steps verification results: ✅ pass On dev NewDot web, a -$100.00 expense with a 5% tax rate kept its negative tax amount (-$4.76) after it was removed from the report and opened in the self DM. The PR's Tests section is still a TODO, so these steps come from the linked issue's reproduction steps.
|
| originalCurrency: getOriginalCurrency(transaction), | ||
| convertedAmount: getConvertedAmount(transaction, isFromExpenseReport, transaction?.reportID === CONST.REPORT.UNREPORTED_REPORT_ID, allowNegativeAmount, disableOppositeConversion), | ||
| convertedTaxAmount: getConvertedTaxAmount(transaction, isFromExpenseReport), | ||
| convertedTaxAmount: getConvertedTaxAmount(transaction, isFromExpenseReport, transaction?.reportID === CONST.REPORT.UNREPORTED_REPORT_ID), |
There was a problem hiding this comment.
@MelvinBot transaction?.reportID === CONST.REPORT.UNREPORTED_REPORT_ID is repeated many times, let's store it in a variable.
Co-authored-by: Bernhard Owen Josephus <bernhardoj@users.noreply.github.com>
|
Done. I moved the check into an
The 28 |
|
@MelvinBot add this to QA Steps Precondition:
Write "Same as QA Steps" for Test and Offline steps |
Codecov Report✅ Changes either increased or maintained existing code coverage, great job!
|
|
I updated the PR description:
I left the "Verify that no errors appear in the JS console" checkboxes in place. |
|
@MelvinBot replace the pr author checklist section with PR Author Checklist
and replace the screenshots/videos with Screenshots/VideosAndroid: NativeAndroid: mWeb ChromeiOS: NativeiOS: mWeb Safariand then check all Verify that no errors appear in the JS console. |
|
🤖 Done. This PR is now marked ready for review. I made these changes to the PR description:
The rest of the description is unchanged. |
|
@ikevin127 Please copy/paste the Reviewer Checklist from here into a new comment on this PR and complete it. If you have the K2 extension, you can simply click: [this button] |
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 2afbbd8566
ℹ️ About Codex in GitHub
Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
| amount: getTransactionAmount(transaction, isFromExpenseReport, isFromTrackedExpense, allowNegativeAmount, disableOppositeConversion), | ||
| attendees: getAttendees(transaction, reportOwnerAsAttendee), | ||
| taxAmount: getTaxAmount(transaction, isFromExpenseReport), | ||
| taxAmount: getTaxAmount(transaction, isFromExpenseReport, isFromTrackedExpense), |
There was a problem hiding this comment.
Preserve positive tracked taxes during edits
When a positive unreported expense's amount, tax rate, or tax amount is edited, getUpdatedTransaction() still stores the positive transactionChanges.taxAmount unchanged because isFromExpenseReport is false for tracked expenses. This new tracked-expense normalization then negates that optimistic value, so the UI shows a negative tax and the update payload produced from getTransactionDetails() sends the negative amount to the API. The edit path must store tracked tax changes using the same opposite-sign convention before applying this normalization.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
@MelvinBot can you explain the above in detail? The flow and the repro steps.
There was a problem hiding this comment.
Codex is right. I reproduced it on this branch on web. If you type a tax amount on a positive unreported expense, the app shows it as negative. For example, entering 3.00 displays -$3.00.
Why: The PR now reads unreported tax with the opposite sign, like amount. But the edit path still saves an edited tax as typed. It doesn't apply the opposite sign:
- getUpdatedTransaction.ts:180 flips
amountforisFromExpenseReport || isUnReportedExpense. - getUpdatedTransaction.ts:384 flips
taxAmountonly forisFromExpenseReport.
Before this PR, Math.abs() hid the mismatch. Now the new read path in ReportUtils.ts:5651 flips the unflipped value.
Fix: At line 384, use isFromExpenseReport || isUnReportedExpense, matching line 180.
Repro steps (workspace with Taxes on and a 5% rate):
- In the workspace chat, create a manual expense for $100.00.
- Open it, select Report, then select Remove from report.
- Open the expense in the self DM. Tax amount shows $4.76.
- Select Tax amount, enter 3.00, and save.
- Tax amount shows -$3.00. It stays negative after you leave and reopen the expense.
Flow and more detail
Flow for a $100 unreported expense, tax set to 3.00:
- DynamicIOURequestStepTaxAmountPage.tsx:125 converts the input to
300and callsupdateMoneyRequestTaxAmount. - UpdateMoneyRequest.ts:1960 sets
isFromExpenseReporttofalsebecause the parent is the self DM. getUpdatedTransactionstorestaxAmount: 300in the optimistic transaction. An unreported expense should store-300.- UpdateMoneyRequest.ts:1980-1986 builds the API params from
getTransactionDetails(updatedTransaction). With this PR,getTaxAmount(..., false, true)returns-300. The UI shows -$3.00, and the request sendstaxAmount: -300(it sent300before this PR).
getUpdateTrackExpenseParams (UpdateMoneyRequest.ts:2600-2616) follows the same pattern with isFromExpenseReport: false.
What I tested:
- Changing the tax rate on the unreported expense showed the correct $4.76 in my test. The rate page passes a positive tax to the same code, so I expected -$4.76. I suspect the server returns a recalculated tax that overwrites the optimistic value, but I didn't verify that.
- On a negative unreported expense, the same gap would likely make an edited tax show as positive. I didn't test this.
- After the fix, check the category-driven tax update at getUpdatedTransaction.ts:410-414 too.
Before the edit, the unreported expense showed tax $4.76. After changing the rate, it still showed $4.76:
There was a problem hiding this comment.
Done in 0ae433f. An edited tax amount on an unreported expense is now stored with the opposite sign, the same way amount is. Entering 3.00 now reads back as $3.00, not -$3.00.
- getUpdatedTransaction.ts:384 now flips
taxAmountforisFromExpenseReport || isUnReportedExpense, matching line 180. - TransactionUtilsTest.ts:1579 adds a test for that case.
TransactionUtilsTest, UpdateMoneyRequestTest and ReportUtilsTest pass (1,997 tests). ESLint, typecheck and cspell are clean. I couldn't run the repro steps on web because the test browser loaded a blank page.
Category-driven tax is not changed
I left the category path at getUpdatedTransaction.ts:413 as is. getCategoryTaxDetails calculates tax from Math.abs of the amount and stores it without a sign flip. Expense report expenses already work this way. I haven't checked whether the server response corrects that optimistic value.
view run · no recording available
Co-authored-by: Bernhard Owen Josephus <bernhardoj@users.noreply.github.com>
|
@bernhardoj Please copy/paste the Reviewer Checklist from here into a new comment on this PR and complete it. If you have the K2 extension, you can simply click: [this button] |
grgia
left a comment
There was a problem hiding this comment.
Changing the category on an unreported expense while offline shows the tax with the wrong sign until the server replies.
if (categoryTaxCode && categoryTaxAmount !== undefined && categoryTaxValue) { updatedTransaction.taxCode = categoryTaxCode; updatedTransaction.taxAmount = categoryTaxAmount; updatedTransaction.taxValue = categoryTaxValue; }
|
Reading through the Melvin analysis, looks like no. |
@grgia do you have a reproduction step for this? I'm so confused about how to reproduce it (specifically, setting the rules; there is only a merchant expense rule). |
|
Repro:
Category tax is computed from if (categoryTaxCode && categoryTaxAmount !== undefined && categoryTaxValue) {
const isNegativeExpense = getAmount(transaction, isFromExpenseReport, isUnReportedExpense) < 0;
const signedCategoryTaxAmount = isNegativeExpense ? -categoryTaxAmount : categoryTaxAmount;
updatedTransaction.taxCode = categoryTaxCode;
updatedTransaction.taxAmount = isFromExpenseReport || isUnReportedExpense ? -signedCategoryTaxAmount : signedCategoryTaxAmount;
updatedTransaction.taxValue = categoryTaxValue;
} |


















Explanation of Change
Unreported (self DM) expenses store their amounts with the opposite sign, just like expense report expenses.
getAmountalready accounts for this with anisFromTrackedExpenseflag, but the tax helpers didn't. So for an unreported expense,normalizeTaxAmountSigntook theMath.abs()branch. A negative expense then showed a positive tax after being removed from a report.This PR:
isFromTrackedExpenseparameter tonormalizeTaxAmountSign,getTaxAmountandgetConvertedTaxAmount, matchinggetAmount.transaction.reportID === CONST.REPORT.UNREPORTED_REPORT_IDfortaxAmountandconvertedTaxAmountingetTransactionDetails, the same way it's already passed foramountandconvertedAmount.getTaxAmountingetTransactionSortValue, so the tax amount column sorts the same way the total amount column does.getTransactionDetailsandgetTransactionSortValue.Positive unreported expenses aren't affected: their stored tax is negative, so flipping the sign gives the same positive value that
Math.abs()gave before.Fixed Issues
$ #103665
PROPOSAL: #103665 (comment)
Tests
Same as QA Steps
Offline tests
Same as QA Steps
QA Steps
Precondition:
PR Author Checklist
### Fixed Issuessection aboveTestssectionOffline stepssectionQA stepssectionAvatar, I verified the components usingAvatarare working as expected)npm run compress-svg)Avataris modified, I verified thatAvataris working as expected in all cases)Designlabel and/or tagged@Expensify/designso the design team can review the changes.mainbranch was merged into this PR after a review, I tested again and verified the outcome was still expected according to theTeststeps.Screenshots/Videos
Android: Native
Android: mWeb Chrome
iOS: Native
iOS: mWeb Safari
MacOS: Chrome / Safari